% demonstrate how to create a dXvirtualTexture instance and modify its
% parameters on the fly

global ROOT_STRUCT
rInit('remote');
ppd = rGet('dXscreen', 1, 'pixelsPerDegree');

% make a list of arguments to set in the GLSL program to which the
% dXvirtualTexture will be attached
w = 20;
h = 1;
glsl = { ...
    'f',    1, ...
    'c',    .5, ...
    'ppd',  ppd, ...
    'pixCenter',    [w h]*ppd/2, ...
    'ColorHigh',    [1 1 1 1], ...
    'ColorLow',     [0 0 0 1]};

% create the dXvirtualTexture.  Attach it to the GLSL program in the
% specified file, and automatically set the the values of GLSL variables
% contained in the GLSLArgs
rAdd('dXvirtualTexture', 1, ...
    'visible',          true, ...
    'file',             'FreqConGabor.frag.txt', ...
    'GLSLArgs',         glsl, ...
    'x',                0, ...
    'y',                0, ...
    'w',                w, ...
    'h',                h, ...
    'GLSLDebugMode',    true, ...
    'sourceRect',       [], ...
    'rotation',         0, ...
    'filterMode',       1, ...
    'globalAlpha',      [], ...
    'modulateColor',    []);

% make some new GLSLArgs to modify texture parameters on the fly!
n = 200;
for c = linspace(0,.9999, n)
    rSet('dXvirtualTexture', 1, 'GLSLArgs', {'c', c});
    rGraphicsDraw;
end
WaitSecs(.5);

for f = exp(linspace(0,1,n))
    rSet('dXvirtualTexture', 1, 'GLSLArgs', {'f', f});
    rGraphicsDraw;
end
WaitSecs(1);

rDone